<!doctype html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!-->
<html lang="en">
<!--<![endif]-->
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="${base}/assets/amazeui/css/amazeui.min.css"/>
    <link rel="stylesheet" href="${base}/assets/amazeui/css/admin.css"/>
    <link rel="stylesheet" href="${base}/assets/amazeui/amazeui-ext.css"/>

    <script src="${base}/assets/amazeui/js/jquery.min.js"></script>
    <script src="${base}/assets/amazeui/js/amazeui.min.js"></script>
    <script type="text/javascript">
        function discuss(productId) {
            $.post("haveDiscuss.htm", {productId: productId}, function (data) {
                if (data == 'success') {
                    $("#discussTextArea").css("display", "");
                } else if (data == 'denru') {
                    alert('请登入');
                    var loginForm = getLoginForm();
                    loginForm.submit();
                }
                else if (data == 'false') {
                    alert('必须购买过该产品才能够评论!');
                }
            });
        }

        function getLoginForm() {
            return document.getElementById("loginForm");
        }
        function insertDiscuss(productId) {
            var disCon = $("#disContent").val();
            if ($.trim(disCon) == "") {
                alert('评论内容不能为空！');
                return false;
            }
            $.post("insertDiscuss.htm", {productId: productId, disCon: disCon}, function (data) {
                if (data == 'success') {
                    alert('发表成功!');
                    getTableForm().submit();
                }
            })
        }

        function getTableForm() {
            return document.getElementById("tableForm");
        }

    </script>
</head>


<body>
<div class="am-container">
<a href="javascript:void(0)" onclick="discuss('${product.id!}');">写评论 </a>

<div id="discussTextArea" style="display:none">
    <textarea rows="6" cols="50" id="disContent"></textarea>
    <button onclick="insertDiscuss('${product.id}');">发表评论</button>
</div>


[#list pagination.list as c]
<div class="am-g">
    <ul>
        <li><strong>${c.member.username!}</strong>&nbsp;&nbsp;<span>发表于 ${c.time!}</span></li>
        <li> ${c.content!}</li>
    </ul>
    <div class="clear"></div>
</div>
[/#list]
[@pagination_style style='8'/]
<form id="loginForm" action="${base!}/login.htm" method="get" target="_top"></form>
<form class="am-form" id="tableForm" action="searchDiscussPage.htm" method="post">
    <input type="hidden" value="${product.id!}" name="productId">
</form>
</div>
</body>
</html>
